//
//  LJHLoginViewController.m
//  HEARME
//
//  Created by mac on 16/2/29.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LJHLoginViewController.h"
@interface LJHLoginViewController ()
@property(nonatomic,retain)UITextField *nameTF;
@property(nonatomic,retain)UITextField *passTF;
@end

@implementation LJHLoginViewController

-(void)dealloc
{
    [_nameTF release];
    [_passTF release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"登录";
    
    UILabel *titleLable = [[UILabel alloc]initWithFrame:CGRectMake(0, 60, WIDTH, 30)];
    titleLable.text = @"登录HEARME用户，即享听觉冲击体验";
    titleLable.font = [UIFont systemFontOfSize:15];
    titleLable.textColor = [UIColor lightGrayColor];
    titleLable.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview: titleLable];
    
    UIImageView *nameImv = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH/10, HEIGHT/5+HEIGHT/50, WIDTH/15, WIDTH/15)];
    //    nameImv.backgroundColor = [UIColor yellowColor];
    nameImv.image = [UIImage imageNamed:@"iconfont-weidenglu.png"];
    [self.view addSubview:nameImv];
    
    self.nameTF = [[UITextField alloc]initWithFrame:CGRectMake((WIDTH/10*2+WIDTH/80), HEIGHT/5+HEIGHT/100,( WIDTH-(WIDTH/10*2+WIDTH/40)-WIDTH/10), WIDTH/10)];
    //    self.nameTF.backgroundColor = [UIColor yellowColor];
    self.nameTF.placeholder = @"请输入手机号...";
    [self.view addSubview:self.nameTF];
    
    UIButton *btnGet = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnGet setTitle:@"获取验证码" forState:UIControlStateNormal];
    btnGet.frame = CGRectMake((WIDTH/10*2+WIDTH/80+WIDTH/4), HEIGHT/5+HEIGHT/100,( WIDTH-(WIDTH/10*2+WIDTH/40)-WIDTH/10), WIDTH/10);
    [btnGet setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [self.view addSubview:btnGet];
    [btnGet addTarget:self action:@selector(getBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *passImv = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH/10, HEIGHT/5+WIDTH/10+WIDTH/20+HEIGHT/100, WIDTH/15, WIDTH/15)];
    //    passImv.backgroundColor = [UIColor yellowColor];
    passImv.image = [UIImage imageNamed:@"iconfont-mima.png"];
    [self.view addSubview:passImv];
    
    self.passTF = [[UITextField alloc]initWithFrame:CGRectMake((WIDTH/10*2+WIDTH/40), HEIGHT/5+WIDTH/10+WIDTH/20,( WIDTH-(WIDTH/10*2+WIDTH/40)-WIDTH/10), WIDTH/10)];
    //    self.passTF.backgroundColor = [UIColor yellowColor];
    self.passTF.placeholder = @"请输入验证码...";
    [self.view addSubview:self.passTF];
    
    UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    loginBtn.frame = CGRectMake(WIDTH/10, HEIGHT/2.5, WIDTH-(WIDTH/10*2), 30);
    loginBtn.backgroundColor = [UIColor lightGrayColor];
    [loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    [loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:loginBtn];
    [loginBtn addTarget:self action:@selector(loginBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH/10, HEIGHT/4*2.5, WIDTH/4, 1)];
    lable.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:lable];
    
    UILabel *lableT = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH/10+WIDTH/3.5, HEIGHT/4*2.45, WIDTH/4, 20)];
    lableT.text = @"使用手机号码登录";
    lableT.font = [UIFont systemFontOfSize:12];
    lableT.textColor = [UIColor lightGrayColor];
    [self.view addSubview:lableT];
    
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH/40+ WIDTH/10+WIDTH/3.5+WIDTH/4, HEIGHT/4*2.5, WIDTH/4, 1)];
    lab.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:lab];
    
    
    // Do any additional setup after loading the view.
}
-(void)getBtn:(UIButton *)btn
{
    NSString *str = self.nameTF.text;
    [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:str zone:@"86" customIdentifier:nil result:^(NSError *error) {
        
        if (!error) {
            NSLog(@"获取验证码成功");
        } else {
            NSLog(@"错误信息：%@",error);
        }
        
    }];
}
-(void)loginBtn:(UIButton *)btn
{
    NSString *str = self.nameTF.text;
    [SMSSDK commitVerificationCode:self.passTF.text phoneNumber:str zone:@"86" result:^(NSError *error) {
        
        if (!error) {
            NSLog(@"验证成功");
        }
        else
        {
            NSLog(@"错误信息:%@",error);
        }
    }];
}
//-(void)tapAction
//{
//    
//    //登录第二步
//    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
//    
//    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],NO,^(UMSocialResponseEntity *response){
//        
//        //          获取微博用户名、uid、token等
//        
//        if (response.responseCode == UMSResponseCodeSuccess) {//登录成功
//            
//            UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
//            
//            NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
//            
//            
//            //登录第三步 ：在登录成功后 获取用户信息
//            
//            //获取accestoken以及新浪用户信息，得到的数据在回调Block对象形参respone的data属性
//            [[UMSocialDataService defaultDataService] requestSnsInformation:UMShareToSina  completion:^(UMSocialResponseEntity *response){
//                [[NSUserDefaults standardUserDefaults]setObject:@"yes" forKey:@"state"];
//                [[NSUserDefaults standardUserDefaults]setObject:snsAccount.userName forKey:@"name"];
//                [[NSUserDefaults standardUserDefaults]setObject:snsAccount.iconURL forKey:@"url"];
//                [[NSUserDefaults standardUserDefaults]setObject:snsAccount.usid forKey:@"usid"];
//                
//                NSLog(@"SnsInformation is %@",response.data);//字典
//                self.dic = response.data;
////                LJHOwnerViewController *owner = [[LJHOwnerViewController alloc]init];
//                
//                [[NSNotificationCenter defaultCenter] postNotificationName:@"change" object:[NSString stringWithString:snsAccount.userName]];
//                
//                [[NSNotificationCenter defaultCenter] postNotificationName:@"changestr" object:@"您已登录"];
//                
//                [[NSNotificationCenter defaultCenter] postNotificationName:@"changeurl" object:[NSString stringWithString:snsAccount.iconURL]];
//                
//                [[NSNotificationCenter defaultCenter] postNotificationName:@"changeuid" object:[NSString stringWithString:snsAccount.usid]];
//                
//                [[NSNotificationCenter defaultCenter] postNotificationName:@"changebtn" object:@"退出"];
//                
//                //                [self.navigationController pushViewController:owner animated:YES];
////                owner.stringName = snsAccount.userName;
////                owner.stringImage = [self.dic objectForKey:@"profile_image_url"];
////                owner.userId = snsAccount.usid;
////                [self.myRefresh refresh];
//                
//                
//            }];
//            
//            [self.navigationController popToRootViewControllerAnimated:YES];
//            
//        }});
//    

    
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
